// pages/courPop/courPop.js
var t = getApp();

Component({
  properties: {
    com_data: {
      type: Object,
      value: ""
    },
    info_data: {
      type: Object,
      value: ""
    },
    show_com: {
      type: Number,
      value: "0"
    },
    pop_show: {
      type: Boolean,
      value: !0
    },
    parentId:{
      type: String,
      value: ''
    }
  },
  data: {
    typetexts:['节','月','季','期','年']
  },
  ready: function(){
  
  },
  methods: {
    return:function(){},
    close_pop:function(){
      var pop_show = !this.properties.pop_show;
      this.triggerEvent('closePop', {pop_show})
    },
    // 报名
    nav_paycour:function(e){
      var id=e.currentTarget.dataset.id,item=e.currentTarget.dataset.item,token=wx.getStorageSync('token'),show_close=true;
      if(token){
        if(item.isLimitQuantity==1&&(item.maxQuantity-item.sellCount)<=0){
          wx.showToast({
            title: '该课程套餐已满员',
            icon: 'none',
            duration: 2000
          })
          show_close=false;
        }else{
          wx.navigateTo({
            url: '../../pages/payCourse/payCourse?id='+id+'&lessonTime='+item.lessonTime+'&type=1',
          })
          show_close=true;
        }
      }else{
        wx.navigateTo({
          url: '../../pages/login/login?parentId='+this.properties.parentId,
        })
        show_close=true;
      }
      if(show_close){
        this.close_pop();
      }
    },
    // 优惠券触底
    scroll_pref_bottom:function(){
      this.triggerEvent('prefScroll',1)
    },
    // 优惠券领取
    get_pref:function(e){
      var index=e.currentTarget.dataset.index;
      this.triggerEvent("getPref",{index})
    },
    // 评论触底
    scroll_com_bottom:function(){
      this.triggerEvent('comCcroll',2)
    },
    // 拼团-参团  type 4-定金参团 5-团购价参团
    nav_pay_group:function(e){
      var item=e.currentTarget.dataset.item,token=wx.getStorageSync('token'),type=4;
      if(token){
        type=item.isDeposit==1?4:5;
        wx.navigateTo({
          url: '../../pages/payCourse/payCourse?id='+item.selMealId+'&lessonTime='+item.lessonTime+'&type='+type+'&group_id='+item.id+'&group_aid='+item.activityId,
        })
      }else{
        wx.navigateTo({
          url: '../../pages/login/login',
        })
      }
      this.close_pop();
    },
    // 生成海报
    canvas_draw:function(){
      this.close_pop();
      this.triggerEvent('canvasDraw',1)
    },
  },
});